package basket;

import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class BasketAction extends ActionSupport 
implements Preparable, ModelDriven{
	
	private BasketVO basket;
	private List<BasketVO> list;
	private int count = 0;
	
	public String getBasketList() throws Exception{
		
		Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
		SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
		
		list=sqlMap.queryForList("selectBasket", basket);
		
		count = list.size();
		
		return SUCCESS;

	}

	public String basketRemove() throws Exception{
		
		Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
		SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
		
		sqlMap.delete("deleteBasket", basket);
		
		return SUCCESS;
	}
	/*public String basketAdd() throws Exception{
		
		Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
		SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
		
		sqlMap.insert("insertAdd", basket);
		
		return SUCCESS;
		
	}*/
	
	public List<BasketVO> getList() {
		return list;
	}

	public void setList(List<BasketVO> list) {
		this.list = list;
	}

	@Override
	public void prepare() throws Exception {
		basket = new BasketVO();
		
	}

	@Override
	public Object getModel() {
		return basket;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

}
